package yxy.banana.server.management;

import java.util.ArrayList;

import yxy.apple.util.RandomUtility;

public class Bundled<V> {
	protected final ArrayList<V> bundling = new ArrayList<>();

	public int size() {
		return this.bundling.size();
	}

	public synchronized void add(V value) {
		this.bundling.add(value);
	}

	public synchronized void remove(V value) {
		this.bundling.remove(value);
	}

	public synchronized V balance() {
		int size = this.bundling.size();
		if (size > 0) {
			int index = RandomUtility.nextInt(0, size);
			return this.bundling.get(index);
		} else {
			return null;
		}
	}
}
